package cn.school.thoughtworks.section2;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PracticeC {
    Map<String, Integer> countSameElements(List<String> collection1) {
        //实现练习要求，并改写该行代码。
        Map<String, Integer> sameElement = new HashMap<String, Integer>();
        for (int i = 0; i < collection1.size(); i++) {
            if (collection1.get(i).length() > 1) {
                String[] strings = collection1.get(i).split("");
                if (strings[1] == ":" || strings[1] == "-") {
                    sameElement.put(strings[0], Integer.parseInt(strings[strings.length - 1]));
                } else {

                    sameElement.put(strings[0], Integer.parseInt(strings[strings.length - 2]));
                }

            } else {
                Integer sum = sameElement.get(collection1.get(i));
                sameElement.put(collection1.get(i), sum == null ? 1 : sum + 1);
            }

        }
        return sameElement;
    }
}

